﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;

namespace UserInterface.Views
{
    using Events;
    using Model;

    /// <summary>
    /// Interaction logic for UnitTemplateCreation.xaml
    /// </summary>
    public partial class UnitTemplateCreation : UserControl
    {
        public UnitTemplateCreation()
        {
            InitializeComponent();
        }

        public event EventHandler<NewTemplateEventArgs> NewTemplate;
        private void OnNewTemplate()
        {
            TemplateInfo template = this.GetTemplateInfo();
            if (NewTemplate != null)
                NewTemplate(this, new NewTemplateEventArgs(template));
        }

        private TemplateInfo GetTemplateInfo()
        {
            return new TemplateInfo(
                uint.Parse(this.HP.Text),
                uint.Parse(this.AP.Text),
                uint.Parse(this.Attack.Text),
                uint.Parse(this.Defence.Text),
                uint.Parse(this.AttackRange.Text)
                );
        }

        private void Button_Click(object sender, RoutedEventArgs e)
        {
            if (IsAttackValid() == true)
                this.OnNewTemplate();
            else
                MessageBox.Show("Some text is not number.");
        }

        private bool IsAllTextBoxValid()
        {
            return this.IsHPValid()
                && this.IsAPValid()
                && this.IsAttackValid()
                && this.IsDefenceValid()
                && this.IsAttackRangeValid();
        }


        private bool IsStringValid(string str)
        {
            uint tmp;
            return uint.TryParse(str, out tmp);
        }

        private bool IsHPValid()
        {
            return this.IsStringValid(this.HP.Text);
        }
        private bool IsAPValid()
        {
            return this.IsStringValid(this.AP.Text);
        }
        private bool IsAttackValid()
        {
            return this.IsStringValid(this.Attack.Text);
        }
        private bool IsDefenceValid()
        {
            return this.IsStringValid(this.Defence.Text);
        }
        private bool IsAttackRangeValid()
        {
            return this.IsStringValid(this.AttackRange.Text);
        }

        
    }
}
